package com.aisino.mplearning.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author guochuantao
 * @version 1.0
 * @description 自动填充处理器
 * @since 2024/8/29 上午10:43
 */

@Slf4j
@Component
public class AutoFillHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("======新增自动插入填充=======");
        // fieldName必须是实体类中的属性名不是表中的字段名  如果书写的是create_date就会失效
        this.strictInsertFill(metaObject, "createDate", Date.class, new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("=======更新自动插入填充=======");
        this.strictUpdateFill(metaObject, "modifyDate", Date.class, new Date());
    }
}
